﻿@using Cinema_Ticketing_System.Models;
@{
    ViewBag.Title = "FilmInformation";
    Layout = "~/Views/Shared/CinemaLayoutPage.cshtml";
}

@section styles{
    <style>
        #main div {
            width: 200px;
            height: 50px;
            line-height: 50px;
            border: 1px solid red;
            text-align: center;
        }

        #upa {
            background-color: orange;
            width: 150px;
            height: 35px;
            line-height: 35px;
            border-radius: 5px;
            text-align: center;
        }

        #box1 {
            height: 230px;
            border-top: 1px black solid;
            margin-top: 10px;
            padding-top: 10px;
        }
        #box2 {
            height: 230px;
            border-top: 1px black solid;
            margin-top: 10px;
            padding-top: 10px;
        }
        #box1 img {
            width: 100%;
            height: 100%;
        }
        #box2 img {
            width: 100%;
            height: 100%;
        }
            
        #main{
            margin-top:10px
        }
    </style>
}
<from class="form-horizontal">
    <div class="col-lg-12" id="main">
        <div class="col-sm-2" id="first">热映电影</div>
        <div class="col-sm-10" id="last">即将上映</div>
    </div>
    <div class="col-lg-12">
        <div class="col-lg-12" id="div1" style="display:block">
            <div id="div1_1">
                @foreach (var item in ViewBag.listshowfilm)
                {
                    <div id="box1" class="col-lg-12">
                        <div class="col-lg-2" style="width:200px;height:200px">
                            <img src="~/imgs/1.jpg" />
                        </div>
                        <div class="col-lg-7">
                            <div>@item.filmname</div>
                            <div>@item.brief_introduction</div>
                            <div>类型：@item.typeid</div>
                            <div>主演：@item.star</div>
                            <div>片长：@item.duration</div>
                        </div>
                        <div class="col-lg-2">
                            <div id="upa">
                                <a href="~/HomePage/Buying_Tickets">
                                    选座购票
                                </a>
                            </div>
                        </div>
                    </div>
                }
            </div>
        <div class="col-lg-12">
            <div></div>
            <div id="one"><a href="#" id="first">第一页</a><a href="#" id="up">上一页</a><a href="#" id="down">下一页</a><a href="#" id="last">尾页</a></div>
        </div>
        </div>
        <div class="col-lg-12" id="div2" style="display:none">
            <div id="div2_1">
                @foreach (var item in ViewBag.listunreleasedfilm)
                {
                    <div id="box2">
                        <div class="col-lg-2">
                            <img src="~/imgs/+@item.cover" />
                        </div>
                        <div class="col-lg-8">
                            <div class="col-lg-12">@item.filmname</div>
                            <div class="col-lg-12">@item.brief_introduction</div>
                            <div class="col-lg-12">类型：@item.typeid</div>
                            <div class="col-lg-12">主演：@item.star</div>
                            <div class="col-lg-12">片长：@item.duration</div>
                        </div>
                        <div class="col-lg-2">
                            <div id="upa">
                                <a href="~/HomePage/Buying_Tickets">
                                    选座购票
                                </a>
                            </div>
                        </div>
                    </div>
                }
            </div>
            <div class="col-lg-12">
                <div></div>
                <div id="two"><a href="#" id="first">第一页</a><a href="#" id="up">上一页</a><a href="#" id="down">下一页</a><a href="#" id="last">尾页</a></div>
            </div>
        </div>
    </div>
    <div class="col-lg-12" style="display:none">
        <ul id="ul1">
            @for (var i = 0; i <= ViewBag.pageNum; i++)
            {
                <li class="active">@i</li>
            }
        </ul>
        <ul id="ul2">
            @for (var i = 0; i <= ViewBag.pageNum2; i++)
            {
                <li class="active">@i</li>
            }
        </ul>
        <div id="cid">@(Session["cid"])</div>
    </div>
</from>

@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>

        $(function () {
            $("#first").click(function () {
                $("#div1").css({ "display": "block" });
                $("#div2").css({ "display": "none" });
            })

            $("#last").click(function () {
                $("#div2").css({ "display": "block" });
                $("#div1").css({ "display": "none" });
            })

            
            $("#upa a").click(function (e) {
                var fid = $(e.target).next().text()
            })

            var cid = $("#cid").text();
            var x = $("#ul1 li:last-child").text();
            var pageIndex = 1;

            $('#one a:first-child').click(function () {
                pageIndex = 1
                $.ajax({
                    url: '/HomePage/FilmInformation',
                    type: 'GET',
                    data: { "requestStatus": 1, "pageIndex": pageIndex,"cid":cid,"fid":fid},
                    success: function (data) {
                        createRow(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })

            })

            $("#one a:nth-child(2)").click(function () {
                if (pageIndex > 1) {
                    pageIndex = pageIndex - 1
                    $.ajax({
                        url: '/HomePage/FilmInformation',
                        type: 'GET',
                        data: { "requestStatus": 1, "pageIndex": pageIndex, "cid": cid, "fid": fid},
                        success: function (data) {
                            createRow(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }

            })

            $("#one a:nth-child(3)").click(function () {
                if (pageIndex < x) {
                    pageIndex = pageIndex + 1
                    $.ajax({
                        url: '/HomePage/FilmInformation',
                        type: 'GET',
                        data: { "requestStatus": 1, "pageIndex": pageIndex, "cid": cid, "fid": fid},
                        success: function (data) {
                            createRow(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }

            })


            $("#one a:last-child").click(function () {
                pageIndex = x
                $.ajax({
                    url: '/HomePage/FilmInformation',
                    type: 'GET',
                    data: { "requestStatus": 1, "pageIndex": pageIndex, "cid": cid, "fid": fid},
                    success: function (data) {
                        createRow(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            })






            var x2 = $("#ul2 li:last-child").text()
            var pageIndex2 = 1
            $('#two a:first-child').click(function () {
                pageIndex2 = 1
                $.ajax({
                    url: '/HomePage/FilmInformation',
                    type: 'GET',
                    data: { "requestStatus": 2, "pageIndex": pageIndex2, "cid": cid, "fid": fid},
                    success: function (data2) {
                        createRow2(data2);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })

            })

            $("#two a:nth-child(2)").click(function () {
                if (pageIndex2 > 1) {
                    pageIndex2 = pageIndex2 - 1
                    $.ajax({
                        url: '/HomePage/FilmInformation',
                        type: 'GET',
                        data: { "requestStatus": 2, "pageIndex": pageIndex2, "cid": cid, "fid": fid},
                        success: function (data2) {
                            createRow2(data2);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }

            })

            $("#two a:nth-child(3)").click(function () {
                if (pageIndex2 < x2) {
                    pageIndex2 = pageIndex2 + 1
                    $.ajax({
                        url: '/HomePage/FilmInformation',
                        type: 'GET',
                        data: { "requestStatus": 2, "pageIndex": pageIndex2, "cid": cid, "fid": fid},
                        success: function (data2) {
                            createRow2(data2);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }

            })


            $("#two a:last-child").click(function () {
                pageIndex2 = x2
                $.ajax({
                    url: '/HomePage/FilmInformation',
                    type: 'GET',
                    data: { "requestStatus": 2, "pageIndex": pageIndex2, "cid": cid, "fid": fid},
                    success: function (data2) {
                        createRow2(data2);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            })

            function createRow2(data2) {
                $('#div2 #box2').remove();
                $.each(data2, function (i, item) {
                    var $div = $(`
                                <div id="box2">
                                    <div class="col-lg-2">
                                        <img src="/imgs/+${item.cover}" />
                                    </div>
                                    <div class="col-lg-8">
                                        <div class="col-lg-12">${item.filmname}</div>
                                        <div class="col-lg-12">${item.brief_introduction}</div>
                                        <div class="col-lg-12">类型：${item.typeid}</div>
                                        <div class="col-lg-12">主演：${item.star}</div>
                                        <div class="col-lg-12">片长：${item.duration}</div>
                                    </div>
                                    <div class="col-lg-2">
                                        <div id="upa">
                                            <a >
                                                选座购票
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                `);
                    $('#div2_1').append($div);
                })
            }

            function createRow(data) {
                $('#div1 #box1').remove();
                $.each(data, function (i, item) {
                    var $div = $(`
                                <div id="box1">
                                    <div class="col-lg-2">
                                        <img src="~/imgs/+${item.cover}" />
                                    </div>
                                    <div class="col-lg-8">
                                        <div class="col-lg-12">${item.filmname}</div>
                                        <div class="col-lg-12">${item.brief_introduction}</div>
                                        <div class="col-lg-12">类型：${item.typeid}</div>
                                        <div class="col-lg-12">主演：${item.star}</div>
                                        <div class="col-lg-12">片长：${item.duration}</div>
                                    </div>
                                    <div class="col-lg-2">
                                        <div id="upa">
                                            <a href="/HomePage/Buying_Tickets">
                                                选座购票
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                `);
                    $('#div1_1').append($div);
                })

            }

        })

    </script>

}
